package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.ResignationApplication;
import org.example.mapper.ResignationApplicationMapper;
import org.example.service.ResignationApplicationService;
import org.springframework.stereotype.Service;

@Service
public class ResignationApplicationServiceImpl extends ServiceImpl<ResignationApplicationMapper, ResignationApplication>
        implements ResignationApplicationService {

    @Override
    public Page<ResignationApplication> getPage(Page<ResignationApplication> page, String keyword, String filter) {
        QueryWrapper<ResignationApplication> queryWrapper = new QueryWrapper<>();

        if (keyword != null && !keyword.isEmpty()) {
            queryWrapper.and(wrapper -> wrapper
                    .like("employee_name", keyword)
                    .or()
                    .like("employee_id", keyword));
        }

        if (filter != null && !filter.isEmpty()) {
            if ("HR已确认".equals(filter)) {
                queryWrapper.eq("hr_confirmation", "已确认");
            } else if ("HR未确认".equals(filter)) {
                queryWrapper.eq("hr_confirmation", "未确认");
            }
        }

        return this.page(page, queryWrapper);
    }
}